package cn.yunyichina.utils.network;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Joe.zhou on 2017/8/7.
 */
public class UrlUtil {

    private static Map<String, String> paramMap = new HashMap<String, String>();

    public static void analysis(String url) {
        paramMap.clear();
        if (!"".equals(url)) {// 如果URL不是空字符串
            url = url.substring(url.indexOf('?') + 1);
            String paramaters[] = url.split("&");
            for (String param : paramaters) {
                String values[] = param.split("=");
                paramMap.put(values[0], values[1]);
            }
        }
    }

    public static String getParam(String name) {
        return paramMap.get(name);
    }

    public static void main(String[] args) {
        String test = "/yyt/wechatpay/wechat/public/callback/dispose?signature=712eb48055b47e7212872bffae1541f262fa17fa&echostr=16698940147376929763&timestamp=1502089891&nonce=2840884768";
        UrlUtil urlAnalysis = new UrlUtil();
        urlAnalysis.analysis(test);
        System.out.println("signature = " + urlAnalysis.getParam("signature"));
        System.out.println("timestamp = " + urlAnalysis.getParam("timestamp"));
    }
}
